package org.example.enums;

import org.example.common.BusinessException;

/**
 * @author liyishan
 * @date 2023/4/18 16:05
 */

public enum RequestMethodEunm {
    GET("GET", "查询操作"),
    HEAD("HEAD", "HEAD请求只会返回首部的信息，不会返回相应体"),
    POST("POST", "POST方法把数据都存放在body里面"),
    PUT("PUT", "用于改变某些内容"),
    PATCH("PATCH", "这个方法不太常见，是servlet 3.0提供的方法，主要用于更新部分字段"),
    DELETE("DELETE", "删除某些资源"),
    OPTIONS("OPTIONS", "客户端查看服务器端的性能"),
    TRACE("TRACE", "回显服务器的请求");

    private String method;
    private String desc;

    public static RequestMethodEunm parse(String val) {
        RequestMethodEunm[] values = values();
        RequestMethodEunm[] var2 = values;
        int var3 = values.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            RequestMethodEunm temp = var2[var4];
            if (val.equals(temp.getMethod())) {
                return temp;
            }
        }

        throw new BusinessException("没有找到此状态 : " + val);
    }

    public String getMethod() {
        return this.method;
    }

    public String getDesc() {
        return this.desc;
    }

    public String toString() {
        return "RequestMethodEunm(method=" + this.getMethod() + ", desc=" + this.getDesc() + ")";
    }

    private RequestMethodEunm(String method, String desc) {
        this.method = method;
        this.desc = desc;
    }

}
